/*
 *@description:首页
 *@Author:@rennan
 *@Date:2024-09-09 08:58:33
 *@version: V1.0.0
*/

<template>
  <div class="home">
    <el-container>
      <el-header class="home_top">
        <div class="top_left">
          <div class="left_logo">logo</div>
          <div class="left_title">系统名称</div>
        </div>
        <!-- 系统头部右侧部分 -->
        <div class="top_right">
          <!-- 折叠按钮 -->
          <div class="top_right_left" @click="handleClick">
            <i class="el-icon-s-fold" v-if="!isCollapse"></i>
            <i class="el-icon-s-unfold" v-else></i>
          </div>
          <div class="top_right_right">
            <div class="right_text">门户网站</div>
            <div class="right_user">欢迎您：xxx</div>
            <el-dropdown trigger="click">
              <span class="el-dropdown-link">
                图片<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item icon="el-icon-plus">个人中心</el-dropdown-item>
                <el-dropdown-item icon="el-icon-circle-plus">回到主页</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '64px' : '200px'">
          <el-menu default-active="1-4-1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
            :collapse="isCollapse" router>
            <div v-for="item in menuList" :key="item.id">
              <el-submenu v-if="hasChildren(item)" :index="item.route">
                <template slot="title">
                  <svg-icon class="nav_icon" :iconClass="item.icon"></svg-icon>
                  <span slot="title">{{ item.name }}</span>
                </template>
                <el-menu-item-group v-for="menu in item.children" :key="menu.id">
                  <el-menu-item :index="menu.route">{{ menu.name }}</el-menu-item>
                </el-menu-item-group>
              </el-submenu>
              <el-menu-item v-else :index="item.route">
                <svg-icon class="nav_icon" :iconClass="item.icon"></svg-icon>
                <span slot="title">{{ item.name }}</span>
              </el-menu-item>
            </div>
          </el-menu>
        </el-aside>
        <el-main>
          <el-card class="box-card">
            <router-view></router-view>
          </el-card>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
// import menuList from './menus.js'
export default {
  data() {
    return {
      isCollapse: false,
      menuList:[]
    }
  },
  methods: {
    // 折叠按钮事件
    handleClick() {
      this.isCollapse = !this.isCollapse
      console.log('点击了折叠按钮');
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    hasChildren(item) {
      if (item.children) {
        return true
      } else {
        return false
      }
    }
  },
  created() {
    this.menuList = menuList
  }
}
</script>
<style lang="less" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.el-container {
  height: calc(100vh - 10px);
}

.el-menu-vertical-demo {
  border: none;
}

.box-card {
  height: 98%;
}

// .el-header {
//   height: 200px;
// }

.home {
  height: 100vh;

  .home_top {
    font-size: 20px;
    font-weight: 600;
    padding: 10px 5px;
    display: flex;
    // justify-content: space-between;
  }

  .top_left {
    width: 200px;
    display: flex;
  }

  .top_right {
    flex: 1;
    display: flex;
    justify-content: space-between;

    .top_right_left {
      cursor: pointer;
    }

    .top_right_right {
      display: flex;
    }
  }
}
</style>